<script>
    let queuedObservers = new Set()

    const observe = (fn) => queuedObservers.add(fn)
    const observerable = (obj) => new Proxy(obj, { set })

    function set(target, key, value, receiver) {
        const result = Reflect.set(target, key, value, receiver)
        queuedObservers.forEach((observe) => observe())
        return result
    }

    const person = observerable({
        name: 'zhangsan',
        age: 20,
    })
    function print() {
        console.log(`${person.name}, ${person.age}`)
    }
    observe(print)
    person.name = 'lisi'
</script>